﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using StackExchange.Redis;

namespace Redis.Controllers
{
    public class HomeController : Controller
    {
        private readonly ILogger<HomeController> _logger;

        public HomeController(ILogger<HomeController> logger)
        {
            _logger = logger;
        }

        public async Task<IActionResult> Index()
        {
            RedisHelperDemo.SetValue("time", DateTime.Now.ToString(), TimeSpan.FromSeconds(20));

            await RedisHelperDemo.SetHasTable("Hash", new HashEntry[] {
                new HashEntry(name:"Age",value:"12"),
                new HashEntry(name:"Sex",value:"女"),
                new HashEntry(name:"Name",value:"黄盖")
            });

            ViewBag.Hash = RedisHelperDemo.GetHasTable("Hash").Result;


            for (int i = 0; i < 10; i++)
            {
                await RedisHelperDemo.SetAddAsync("MySet", i.ToString());
            }

            return View();
        }



        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {
            // return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
            return View();
        }
    }
}
